#include "Canny.h"
#include "../utils/Logger.h"

Canny::Canny(int lowThreshold, int highThreshold, int aperture) :
        lowThreshold(lowThreshold),
        highThreshold(highThreshold),
        aperture(aperture)
{
}

Canny::~Canny() {
}

IplImage* Canny::apply(const IplImage* in) {
    Log << "Applying canny effect: " <<
            lowThreshold << ", " <<
            highThreshold << ", " <<
            aperture << endl;

    bool releaseIn = false;
    if (in->nChannels != 1) {
        in = grayEffect.apply(in);
        releaseIn = true;
    }

    IplImage *out = cvCreateImage(cvSize(in->width, in->height), in->depth, in->nChannels);
    cvCanny(in, out, lowThreshold, highThreshold, aperture);

    if (releaseIn)
        cvReleaseImage((IplImage**) &in);

    return out;
}
